import { defineConfig, loadEnv } from 'vite'
import createVitePlugins from './src/ebdmn/index'
const path = require('path')
// https://vitejs.dev/config/
// mode server
// command 环境 development
export default ({ mode, command }) => {
  // 获取环境变量
  const env = loadEnv(mode, process.cwd())
  return defineConfig({
    base: './',
    // 开发服务器选项 https://cn.vitejs.dev/config/#server-options
    server: {
      open: true,
      port: 3000,
      proxy: {
        '/auth': {
          target: 'http://www.hnxxgs.com.cn:8000',
          changeOrigin: true
        },
        '/basic': {
          target: 'http://www.hnxxgs.com.cn:8000',
          changeOrigin: true
        }
        // '/auth': 'http://www.hnxxgs.com.cn:8080',
        // '/basic': 'http://www.hnxxgs.com.cn:8080'
        // '/dev-api': {
        //   target: 'http://127.0.0.1:8080',
        //   changeOrigin: command === 'serve' && env.VITE_OPEN_PROXY == 'true',
        //   rewrite: path => path.replace(/\/dev-api/, '')
        // }
      }
    },
    resolve: {
      alias: {
        '@': path.resolve('src'),
        '~@': path.resolve('src'),
        '@config': path.resolve('src/config'),
        '@components': path.resolve('src/components'),
        '@layout': path.resolve('src/layout'),
        '@store': path.resolve('src/store'),
        '@styles': path.resolve('src/styles'),
        '@router': path.resolve('src/router'),
        '@assets': path.resolve('src/assets'),
        '@utils': path.resolve('src/utils'),
        '*': path.resolve('')
      }
    },
    plugins: createVitePlugins(env, command === 'build'),
    // vite2.x
    css: {
      preprocessorOptions: {
        less: {
          javascriptEnabled: true
        }
      }
    }
  })
}

